package com.gxa.modules.sys.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.AssertUtils;
import com.gxa.common.utils.PageUtils;
import com.gxa.modules.community.util.Result;
import com.gxa.modules.sys.entity.*;
import com.gxa.modules.sys.service.ComplaintTypeService;
import com.gxa.modules.sys.service.MapManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "Banner图管理 接口")
@RestController
@Slf4j
public class MapManagementController {
    @Autowired
    private MapManagementService mapManagementService;

    @ApiOperation(value="Banner图管理 查询 (查询条件Banner名称)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "bannerName",value = "Banner名称",dataType ="String"),
    })
    @GetMapping("/mapManagement/list")
    public Result<List<MapManagement>> mapManagementList(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        AssertUtils.isBlank(String.valueOf(params), "字符串不为能空");

        Result<List<MapManagement>> r = Result.success();
        try {
            PageInfo<MapManagement> pageInfo = mapManagementService.queryMapManagement(params);
            r = Result.success(pageInfo.getList(),pageInfo.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            r = Result.failed();
        }
        return r;
    }

    @ApiOperation(value="Banner图管理 添加")
    @PostMapping("/mapManagement/add")
    public com.gxa.common.utils.Result<PageUtils> mapManagementAdd(@RequestBody MapManagementMapperAdd mapManagementMapperAdd) {
        mapManagementMapperAdd.setBannerState("1");
        log.info("----complaintTypeAdd-----{}----", mapManagementMapperAdd);
        AssertUtils.isBlank(String.valueOf(mapManagementMapperAdd), "字符串不为能空");
        this.mapManagementService.addMapManagement(mapManagementMapperAdd);
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

    @ApiOperation(value="Banner图管理 修改")
    @PutMapping("/mapManagement/update")
    public com.gxa.common.utils.Result<PageUtils> mapManagementUpdate(@RequestBody MapManagementMapperUpdate mapManagementMapperUpdate) {
        log.info("----mapManagementMapperUpdate-----{}----", mapManagementMapperUpdate);
        AssertUtils.isBlank(String.valueOf(mapManagementMapperUpdate), "字符串不为能空");
        this.mapManagementService.updateMapManagement(mapManagementMapperUpdate);
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

    @ApiOperation(value="Banner图管理 删除")
    @DeleteMapping("/mapManagement/delete")
    public com.gxa.common.utils.Result<PageUtils> mapManagementDalete(@RequestBody Integer[] ids) {
        log.info("----ids-----{}----", ids);
        AssertUtils.isBlank(String.valueOf(ids), "字符串不为能空");
        for (Integer id:ids){
            System.out.println(id);
            this.mapManagementService.deleteMapManagement(id);
        }
        return new com.gxa.common.utils.Result<PageUtils>().ok();
    }

}
